home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / AmigaTalk_X / system / ParallelDevice.st < prev    next >
Encoding:
Text File  |  2002-03-13  |  3.4 KB  |  118 lines

  1. " ----------------------------------------------------------------------"
  2. " ParallelDevice Class is derived from abstract Device Class.           "
  3.  
  4. "  WARNING:  You should know what you're doing to the Amiga OS before   "
  5. "            messing with this Class, or any other System Class!        " 
  6.  
  7. " This class is a Singleton Class.  In the future, this class will be   "
  8. " modified to allow more than one Parallel port to be open at a time    "
  9. " (for those of us fortunate enough to have more than one Parallel Port."
  10.  
  11. " NOTES
  12.  
  13.   newParms & parallelFlags can have any of the following values:
  14.  
  15.     2r00000010 PARF_EOFMODE  - check I/O against the TermChars array.
  16.     2r00000100 PARF_ACKMODE  - use ACK handshaking.
  17.     2r00001000 PARF_FASTMODE - Send out data as long as BUSY is low. 
  18.     2r00010000 PARF_SLOWMODE - For transfers to slow printers.
  19.     2r00100000 PARF_SHARED   - Allow sharing of the parallel device.    "
  20.  
  21. " ----------------------------------------------------------------------"
  22.  
  23. Class ParallelDevice :Device ! uniqueInstance !
  24. [
  25.    status
  26.  
  27. "  The returned status has the following meaning:
  28.  
  29.     BIT:  ACTIVE:  FUNCTION:
  30.  
  31.      0      HIGH   Printer Busy toggle (offline).
  32.      1      HIGH   Paper out.
  33.      2      HIGH   Printer Select.
  34.      3      ----   Read = 0, Write = 1
  35.      4-7    ----   Reserved.
  36. "
  37.       ^ <primitive 224 3>
  38. |
  39.    resetPort
  40.       ^ <primitive 224 4>
  41. |                  
  42.    flushPort
  43.       ^ <primitive 224 5>
  44. |                  
  45.    stopPort
  46.       ^ <primitive 224 6>
  47. |                  
  48.    startPort
  49.       ^ <primitive 224 7>
  50. |                  
  51.    setPortParametersTo: newParms
  52.       ^ <primitive 224 8 newParms>
  53. |                  
  54.    readThisMany: numChars
  55.       ^ <primitive 224 9 numChars>
  56. |
  57.    writeToPort: aString thisLong: numChars ! check !
  58.       check <- <primitive 224 10 numChars aString>.
  59.       
  60.       (check ~= numChars)
  61.          ifTrue: [ 'Parallel Port write error!' print]
  62. |                  
  63.    setTerminatorsTo: aString
  64.       "Only the first 4 characters of the string are used."
  65.       ^ <primitive 224 11 aString>
  66. |                  
  67.    setPortDirectionAtomic: rwFlag
  68.       " Not needed for reading & writing to the Parallel Port."
  69.       ^ <primitive 224 12 rwFlag>
  70. |                  
  71.    sendPortControlBits: newBits
  72.       " Only the 3 least-significant bits will be written to the hardware.
  73.         This is to prevent your code from interfering with the Serial
  74.         device.
  75.       "
  76.       ^ <primitive 224 13 newBits>
  77. |                  
  78.    readControlBitsMaskedBy: ctrlMask
  79.       " Only the 3 least-significant bits have any meaning 
  80.         for the Parallel Port.  Use ctrlMask of seven (7).
  81.       "
  82.       ^ <primitive 224 14 ctrlMask>
  83. |
  84.    open: parallelFlags ! check !
  85.    
  86.       check <- <primitive 224 1 parallelFlags>.
  87.  
  88.       (check ~= 0)
  89.          ifTrue: [ 'Error open Parallel device:' print.
  90.                    <primitive 224 2 check> print.
  91.                    ^ nil
  92.                  ].
  93.       ^ self
  94. |
  95.    close
  96.       <primitive 224 0>
  97. |
  98.    new 
  99.       ^ self current
  100. |
  101.    current
  102.       (uniqueInstance isNil)
  103.          ifTrue: [ uniqueInstance <- self basicNew ].
  104.       
  105.       ^ uniqueInstance
  106. |
  107.    current: parallelFlags
  108.       (uniqueInstance isNil)
  109.          ifTrue: [ uniqueInstance <- self basicNew.
  110.                    self open: parallelFlags
  111.                  ].
  112.       
  113.       ^ uniqueInstance
  114. |
  115.    new: parallelFlags
  116.       ^ (self current: parallelFlags)
  117. ]
  118.